//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.farm.doc.util;

import com.farm.doc.domain.FarmDoctype;
import com.farm.doc.domain.ex.DocEntire;
import com.farm.doc.domain.ex.FqaBrief;
import com.farm.lucene.adapter.DocMap;
import java.util.Iterator;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;

public class LuceneDocUtil {
    public LuceneDocUtil() {
    }

    public static DocMap getDocMap(DocEntire doc) {
        String text = "";
        if (doc.getTexts() != null) {
            text = doc.getTexts().getText1();
        }

        text = HtmlUtils.HtmlRemoveTag(text);
        DocMap map = new DocMap(doc.getDoc().getId());
        String typeAll = "";
        if (doc.getCurrenttypes() != null) {
            Iterator var5 = doc.getCurrenttypes().iterator();

            while(var5.hasNext()) {
                FarmDoctype node = (FarmDoctype)var5.next();
                if (typeAll.equals("")) {
                    typeAll = node.getName();
                } else {
                    typeAll = typeAll + "/" + node.getName();
                }
            }

            map.put("TYPENAME", typeAll, Store.YES, Index.ANALYZED);
            map.put("TYPEID", doc.getType().getId(), Store.YES, Index.NO);
        }

        map.put("TAGKEY", doc.getDoc().getTagkey(), Store.YES, Index.ANALYZED);
        map.put("TITLE", doc.getDoc().getTitle(), Store.YES, Index.ANALYZED);
        map.put("AUTHOR", doc.getDoc().getAuthor(), Store.YES, Index.ANALYZED);
        map.put("DOCDESCRIBE", doc.getDoc().getDocdescribe(), Store.YES, Index.ANALYZED);
        map.put("VISITNUM", "0", Store.YES, Index.ANALYZED);
        map.put("PUBTIME", doc.getDoc().getPubtime(), Store.YES, Index.ANALYZED);
        map.put("USERID", doc.getDoc().getCuser(), Store.YES, Index.ANALYZED);
        map.put("DOMTYPE", doc.getDoc().getDomtype(), Store.YES, Index.ANALYZED);
        map.put("TEXT", text, Store.YES, Index.ANALYZED);
        map.put("DOCID", doc.getDoc().getId(), Store.YES, Index.ANALYZED);
        map.put("GROUPID", doc.getDoc().getDocgroupid(), Store.YES, Index.ANALYZED);
        map.put("READPOP", doc.getDoc().getReadpop(), Store.YES, Index.ANALYZED);
        return map;
    }

    public static DocMap convertFileMap(DocMap docmap, String fileId, String title, String text) {
        docmap.put("DOCID", docmap.getValue("ID"), Store.YES, Index.ANALYZED);
        docmap.put("ID", fileId, Store.YES, Index.ANALYZED);
        docmap.put("DOMTYPE", "file", Store.YES, Index.ANALYZED);
        docmap.put("TEXT", text, Store.YES, Index.ANALYZED);
        docmap.put("TITLE", title, Store.YES, Index.ANALYZED);
        return docmap;
    }

    public static DocMap getDocMap(FqaBrief fqabrief) {
        DocMap map = new DocMap(fqabrief.getQuestionid());
        if (fqabrief.getTypes() != null) {
            map.put("TYPENAME", fqabrief.getTypeAll(), Store.YES, Index.ANALYZED);
            if (fqabrief.getType() != null) {
                map.put("TYPEID", fqabrief.getType().getId(), Store.YES, Index.NO);
            }
        }

        map.put("TAGKEY", fqabrief.getTags(), Store.YES, Index.ANALYZED);
        map.put("TITLE", fqabrief.getTitle(), Store.YES, Index.ANALYZED);
        map.put("AUTHOR", fqabrief.getAuthor(), Store.YES, Index.ANALYZED);
        map.put("DOCDESCRIBE", fqabrief.getDescribe(), Store.YES, Index.ANALYZED);
        map.put("VISITNUM", fqabrief.getVisitnum(), Store.YES, Index.ANALYZED);
        map.put("PUBTIME", fqabrief.getPubtime(), Store.YES, Index.ANALYZED);
        map.put("USERID", fqabrief.getUserid(), Store.YES, Index.ANALYZED);
        map.put("DOMTYPE", "fqa", Store.YES, Index.ANALYZED);
        map.put("TEXT", fqabrief.getText(), Store.YES, Index.ANALYZED);
        map.put("DOCID", "NONE", Store.YES, Index.ANALYZED);
        map.put("GROUPID", "NONE", Store.YES, Index.ANALYZED);
        map.put("READPOP", "1", Store.YES, Index.ANALYZED);
        map.put("STATE", fqabrief.getState(), Store.YES, Index.ANALYZED);
        return map;
    }
}
